package cn.com.gridinfo.sooc.core.expand.callname.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.marshalchen.ultimaterecyclerview.UltimateRecyclerviewViewHolder;
import com.marshalchen.ultimaterecyclerview.UltimateViewAdapter;

import java.util.List;

import cn.com.gridinfo.sooc.R;
import cn.com.gridinfo.sooc.core.expand.callname.bean.ClassInfo;

/**
 * 缺席课堂界面列表适配器
 *
 * @author yingchunli
 */
public class QueXiClassAdapter extends UltimateViewAdapter<QueXiClassAdapter.ViewHolder> {

    public List<ClassInfo> classInfoList;
    Context context;
    private String kcmc;//课程名称

    public QueXiClassAdapter(List<ClassInfo> classInfoList, Context context,String kcmc) {
        this.classInfoList = classInfoList;
        this.context = context;
        this.kcmc=kcmc;
    }

    @Override
    public RecyclerView.ViewHolder onCreateHeaderViewHolder(ViewGroup parent) {
        return null;
    }

    @Override
    public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder, int position) {

    }

    @Override
    public ViewHolder getViewHolder(View view) {
        return new ViewHolder(view, false);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent) {
        //加载布局
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.expand_callname_quexiclass_item, parent, false);

        return new ViewHolder(view, true);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        if (position < getItemCount() &&
                (customHeaderView != null ? position <= classInfoList.size() : position < classInfoList.size())
                && (customHeaderView != null ? position > 0 : true)) {
            ClassInfo classInfo = classInfoList.get(position);
            holder.kcmc.setText(kcmc);
            holder.ktzt.setText(classInfo.getKtzt());
            holder.time.setText(classInfo.getSkrq());
            //底部分割线的显示
//            if (position == classInfoList.size() - 1) {
//                holder.line.setVisibility(View.VISIBLE);
//            } else {
//                holder.line.setVisibility(View.GONE);
//            }
        }
    }

    public void loadmore(List<ClassInfo> list) {
        classInfoList.addAll(list);
        notifyDataSetChanged();
    }

    public void refresh(List<ClassInfo> list) {
        classInfoList.clear();
        classInfoList.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public int getAdapterItemCount() {
        return classInfoList.size();
    }

    @Override
    public long generateHeaderId(int position) {
        return position;
    }

    //ViewHolder
    public class ViewHolder extends UltimateRecyclerviewViewHolder {
        TextView kcmc, time, ktzt;
//        View line;

        public ViewHolder(View itemView, boolean isItem) {
            super(itemView);
            if (isItem) {
                kcmc = (TextView) itemView.findViewById(R.id.ktmc_quexiclass_item);//课程名称
                ktzt=(TextView)itemView.findViewById(R.id.ktzt_quexiclass_item);//课堂主题
                time=(TextView)itemView.findViewById(R.id.time_quexiclass_item);//时间
//                line = (View) itemView.findViewById(R.id.line_bottom);//底部分割线
            }
        }
    }
}
